import { Controller, Get, Param, ParseIntPipe, Query } from '@nestjs/common';
import { ApiOperation, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger';
import { PublicPostsService, PublicQuery } from './public.posts.service';
import { Throttle } from '@nestjs/throttler';

@ApiTags('Public Posts')

@Controller('public/posts')
export class PublicPostsController {
  constructor(private readonly publicPostsService: PublicPostsService) { }
  @Get()
  @ApiOperation({ summary: '公开-分页获取已发布文章' })
  @ApiQuery({ name: 'page', required: false, type: Number })
  @ApiQuery({ name: 'limit', required: false, type: Number })
  @ApiQuery({ name: 'search', required: false, type: String })
  @ApiQuery({ name: 'tag', required: false, type: String })
  @ApiQuery({ name: 'categoryId', required: false, type: Number })
  async list(@Query() query: PublicQuery) {
    return await this.publicPostsService.list(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '公开-根据ID获取文章详情' })
  @ApiParam({ name: 'id', description: '文章ID' })
  async byId(@Param('id', ParseIntPipe) id: number) {
    return await this.publicPostsService.byId(id);
  }

  @Get('slug/:slug')
  @ApiOperation({ summary: '公开-根据slug获取文章详情' })
  @ApiParam({ name: 'slug', description: '文章slug' })
  async bySlug(@Param('slug') slug: string) {
    return await this.publicPostsService.bySlug(slug);
  }
}


